package com.cuitrip.business.home.arrange.ui;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.cuitrip.business.home.arrange.model.MonthCalendar;
import com.cuitrip.service.R;
import com.cuitrip.util.time.TimeUtil;
import com.lab.adapter.BaseHolderView;
import com.lab.adapter.IAdapterData;
import com.lab.widget.CtGridView;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.Bind;

/**
 * Created by ak on 15/10/16.
 */
public class MonthHolderView extends BaseHolderView {

    private MonthDateAdapter monthDateAdapter;

    @Bind(R.id.month_title)
    TextView monthView;

    @Bind(R.id.date_week_grid)
    CtGridView gridView;

    public MonthHolderView(Context context) {
        super(context, R.layout.item_month_date_view);
    }

    private MonthDateAdapter.OnSelectChangeCallBack onSelectChangeCallBack;

    public void setOnSelectChangeCallBack(MonthDateAdapter.OnSelectChangeCallBack onSelectChangeCallBack){
        this.onSelectChangeCallBack = onSelectChangeCallBack;
    }

    @Override
    public void initView(View rootView) {
        this.setClickable(true);
        ButterKnife.bind(this);
        monthDateAdapter = new MonthDateAdapter(mContext, true);
        gridView.setAdapter(monthDateAdapter);
        monthDateAdapter.setOnSelectChangeCallBack(new MonthDateAdapter.OnSelectChangeCallBack() {
            @Override
            public void onSelectRemove(Long time) {
                if (onSelectChangeCallBack != null){
                    onSelectChangeCallBack.onSelectRemove(time);
                }

            }

            @Override
            public void onSelectAdd(Long time) {
                if (onSelectChangeCallBack != null){
                    onSelectChangeCallBack.onSelectAdd(time);
                }
            }

        });
    }

    public void setBookDateList(List<Long> bookDateList) {
        monthDateAdapter.setBookDateList(bookDateList);
    }

    public void setAvailableDateList(List<Long> availableDateList) {
        monthDateAdapter.setAvailableDateList(availableDateList);
    }

    @Override
    public void bindData(final IAdapterData data, final int position) {
        if (data instanceof MonthCalendar) {
            MonthCalendar monthCalendar = (MonthCalendar) data;
            monthDateAdapter.setCalendar(monthCalendar.getCalendar());
            monthView.setText(TimeUtil.formatMonth(monthView.getContext(),monthCalendar.getCalendar().getTime().getTime()));
            monthDateAdapter.notifyDataSetChanged();
        }
    }

}
